package com.test.zhangxin.jianpin.presenter;

import android.util.Log;

import com.test.zhangxin.jianpin.MyApplication;
import com.test.zhangxin.jianpin.ServerApi;
import com.test.zhangxin.jianpin.bean.Template;
import com.test.zhangxin.jianpin.view.TemplateView;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by admin on 2017/6/19.
 */

public class TemplatePresenter {
    private TemplateView mTemplate;
    MyApplication mApplication;
    private ServerApi mApi;

    public TemplatePresenter(TemplateView template) {
        mTemplate = template;
        mApplication = new MyApplication();
        mApi = mApplication.getApi();
    }

    public void getTemplateList() {
        mApi.getTemplate().enqueue(new Callback<List<Template>>() {
            @Override
            public void onResponse(Call<List<Template>> call, Response<List<Template>> response) {
                List<Template> templateList = response.body();
                if (templateList != null){
                    mTemplate.getDataSuccessful(templateList);
                }
            }

            @Override
            public void onFailure(Call<List<Template>> call, Throwable t) {
                Log.e("zx", "failed");
                Log.e("zx", "error::" + t);
                mTemplate.getDataFailed();
            }
        });
    }


}
